package com.kangye.learnteacher.controller;

import com.kangye.learnteacher.entity.User;
import com.kangye.learnteacher.service.loginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @program: learndeduo
 * @description: 用户登录
 * @author: 李豪杰
 * @create: 2021-05-17 08:41
 **/
@RestController
@CrossOrigin
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private loginService loginservice;

    /**
     * 登录
     * @param userName
     * @param userPassword
     * @param request
     * @return
     */
    @RequestMapping("/login")
    public User userLogin(String userName, String userPassword, HttpSession request){
        User user = loginservice.userLogin(userName);

        //判断密码是否一致
        if(userPassword.equals(user.getUserPassword())){
            request.setAttribute("lookpersonaldata",user);
            return user;
        }else{
            user.setUserUserName("201");
            return user;
        }
    }


}
